package org.jsbd.boss.task;

import org.jsbd.boss.service.IChannelMonitorNewUsers;
import org.jsbd.boss.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * mark和设备数定时刷新
 * 
 * @author zbh
 * 
 */
public class ChannelMonitorNewUsersTask implements Runnable {


	public static final Logger LOGGER = LoggerFactory.getLogger(ChannelMonitorNewUsersTask.class);

	@Autowired
	private IChannelMonitorNewUsers channelMonitorNewUsers;
	
	// 默认是开的
	private static final String RUN_FLAG = "on";
	
	private static final int email_report_time = PropertiesUtil.getInt("email_report_time", 5);

	public void start() {
		String flag = PropertiesUtil.getValue("email_report_flag", "on");
		if (!RUN_FLAG.equalsIgnoreCase(flag)) {
			return;
		} else {
			Thread t = new Thread(this);
			t.start();
		}
	}

	@Override
	public void run() {
		while (true) {
			try {
				channelMonitorNewUsers.reportNewUsers();
			} catch (Exception e) {
				LOGGER.error("Any error msg that u want to write", e);
			} finally {
				try {
					Thread.sleep(1000 * 60 * email_report_time);
				} catch (InterruptedException e) {
					LOGGER.error("Any error msg that u want to write", e);
				}
			}
		}

	}


}
